/*
 * @Author: szx
 * @Date: 2021-12-01 13:20:35
 * @LastEditTime: 2021-12-01 13:27:31
 * @Description:
 * @FilePath: \leetcode\1-99\27\27.js
 */
/**
 * @param {number[]} nums
 * @param {number} val
 * @return {number}
 */
var removeElement = function (nums, val) {
    let slow = 0;
    for (let i = 0; i < nums.length; i++) {
        if (val != nums[i]) {
            nums[slow] = nums[i];
            slow++;
        }
    }
    return slow;
};
var removeElement = function(nums, val) {
    let left = 0, right = nums.length;
    while (left < right) {
        if (nums[left] === val) {
            nums[left] = nums[right - 1];
            right--;
        } else {
            left++;
        }
    }
    return left;
};
